package com.ganee.agora.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProviders
import com.ganee.agora.R
import com.ganee.agora.event.AmountEvent
import com.ganee.agora.viewmodel.SettingsViewModel
import com.ganee.baselib.mvvmlibrary.base.BaseActivity
import kotlinx.android.synthetic.main.activity_amount_input_acitvity.*
import kotlinx.android.synthetic.main.toolbar_back.*
import org.greenrobot.eventbus.EventBus

class AmountInputActivity : BaseActivity<SettingsViewModel>(), View.OnClickListener {


    override fun getViewModel(): SettingsViewModel {
        return ViewModelProviders.of(this@AmountInputActivity).get(SettingsViewModel::class.java)
    }

    private var amount:String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_amount_input_acitvity)

        val bundle = intent.extras
        if (bundle != null) {
            amount = bundle.getString("amount")
        }

        initView()
    }

    private fun initView() {
        toolbarBack.setOnClickListener(this)
        amount_tv_confirm.setOnClickListener(this)
        if (amount!!.toDouble() > 0){
            amount_et_money.setText(amount)
        }
    }

    override fun onClick(v: View?) {
        when(v!!.id){
            R.id.toolbarBack -> {
                finish()
            }
            R.id.amount_tv_confirm -> {
                EventBus.getDefault().post(AmountEvent("amount",amount_et_money.text.toString()))
                finish()
            }
        }
    }
}
